//涉及table相关的函数

//查询全部的货物
function selectGoods(data){
    var table = document.getElementById('table-goods')

    var rowNum=table.rows.length;
    if(rowNum>0)
    {
        for(i=1;i<rowNum;i++)
        {
            table.deleteRow(i);
            rowNum=rowNum-1;
            i=i-1;
        }
    }



    for(var i=0;i<data.goodId.length;++i){
        var temp = new Array()
        temp[0] = data.goodId[i];
        temp[1] = data.goodName[i];
        temp[2] = data.goodPrice[i];
        addGoods(table,temp)
    }

}
//给货物表格添加数据
function addGoods(table, data){
    var tr = document.createElement('tr')
    var td1 = document.createElement('td')
    var td2 = document.createElement('td')
    var td3 = document.createElement('td')
    td1.innerText = data[0]
    td2.innerText = data[1]
    td3.innerText = data[2]
    tr.appendChild(td1)
    tr.appendChild(td2)
    tr.appendChild(td3)

    table.appendChild(tr)
}

//查询用户信息
function selectDetails(data){
    /*
    var table = document.getElementById('table-user')
    var rowNum=table.rows.length;
    if(rowNum>0)
    {
        for(i=1;i<rowNum;i++)
        {
            table.deleteRow(i);
            rowNum=rowNum-1;
            i=i-1;
        }
    }



    var table = document.getElementById('table-user')
    var tr = document.createElement('tr')
    var td1 = document.createElement('td')
    var input1 = document.createElement('input')
    input1

    var td2 = document.createElement('td')
    var td3 = document.createElement('td')
    var td4 = document.createElement('td')
    var td5 = document.createElement('td')


    td1.innerText = data.userId;
    td2.innerText = data.userName;
    td3.innerText = data.address;
    td4.innerText = data.age;
    td5.innerText = data.sex;

    tr.appendChild(td1)
    tr.appendChild(td2)
    tr.appendChild(td3)
    tr.appendChild(td4)
    tr.appendChild(td5)

    table.appendChild(tr)*/
    var userid = document.getElementById("details_id");
    var username = document.getElementById("details_username");
    var address = document.getElementById("details_address");
    var age = document.getElementById("details_age");
    var sex = document.getElementById("details_sex");

    userid.innerText = data.userId;
    username.innerText =data.userName;
    address.value = data.address;
    age.value = data.age;
    sex.value = data.sex;
}

//查询订单信息
function selectOrders(data) {
    var table = document.getElementById('table-orders')

    var rowNum = table.rows.length;
    if (rowNum > 0) {
        for (i = 1; i < rowNum; i++) {
            table.deleteRow(i);
            rowNum = rowNum - 1;
            i = i - 1;
        }
    }


    for (var i = 0; i < data.orderId.length; ++i) {
        var temp = new Array()
        temp[0] = data.orderId[i];
        temp[1] = data.userName[i];
        temp[2] = data.address[i];
        temp[3] = data.goodName[i];
        addOrders(table, temp)
    }
}

    //给货物表格添加数据
    function addOrders(table, data){
        var tr = document.createElement('tr')
        var td1 = document.createElement('td')
        var td2 = document.createElement('td')
        var td3 = document.createElement('td')
        var td4 = document.createElement('td')
        td1.innerText = data[0]
        td2.innerText = data[1]
        td3.innerText = data[2]
        td4.innerText = data[3]
        tr.appendChild(td1)
        tr.appendChild(td2)
        tr.appendChild(td3)
        tr.appendChild(td4)

        table.appendChild(tr)
    }

function showResult(data){

    function addResult(table, data){
        var tr = document.createElement('tr')
        var td1 = document.createElement('td')
        var td2 = document.createElement('td')
        var td3 = document.createElement('td')
        var td4 = document.createElement('td')
        td1.innerText = data[0]
        td2.innerText = data[1]
        td3.innerText = data[2]
        td4.innerText = data[3]
        tr.appendChild(td1)
        tr.appendChild(td2)
        tr.appendChild(td3)
        tr.appendChild(td4)

        table.appendChild(tr)
    }



    var table = document.getElementById("table-showResult");

    var rowNum = table.rows.length;
    if (rowNum > 0) {
        for (i = 1; i < rowNum; i++) {
            table.deleteRow(i);
            rowNum = rowNum - 1;
            i = i - 1;
        }
    }
    if(data.ip.length<=0)
        return;
    if(data.ip[0]=="")
        return;
    for (var i = 0; i < data.ip.length-1; ++i) {
        var temp = new Array()
        temp[0] = i+1;
        temp[1] = data.ip[i];
        temp[2] = data.sql[i];
        temp[3] = data.time[i];
        addResult(table, temp)
    }



}